﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Shared;


namespace OnlineShop
{
    class LoginPresenter
    {
        private ILogin _loginView;
        private IUserRepository _user;        

        public LoginPresenter(ILogin login, IUserRepository user)
        {
            _loginView = login;
            _user = user;

            _loginView.OkPressed += _loginView_OkPressed;
            _loginView.CancelPressed += _loginView_CancelPressed;
        }

        public void _loginView_CancelPressed()
        {
            this._loginView.Close();
        }

        public void _loginView_OkPressed()
        {
            if (_user.IsPassLoginValid(_loginView.tbLogin(), _loginView.tbPass()))
                this._loginView.Close();
            else this._loginView.Message();
        }

        public void Run()
        {
            this._loginView.Show();
        }
    }
}
